<template>
	<view class="">
		<view class="eachjie-box" @click="eacha()">
			<image :src="imga" mode="heightFix" class="fixed-height-img"></image>
		</view>
		<view class="const-box">
			<view class="const-box-as" @click="tiaozhuan(item)" v-for="(item ,index) in tupancli" :key="index">
				<view style="width: 43vw;">
					<image class="imgaserrr" style="width: 43vw;" :src="item.coverList[0].url" mode="widthFix"></image>
				</view>
				<view class="textname">
					{{item.name}}
				</view>
				<!-- <image src="../../static/images/stro/分享.svg" class="imgase"  mode="widthFix"></image> -->
			</view>
		</view>
	</view>
</template>

<script>
	import api from '../../api/Channel.js';
	import commonMixin from '@/mixins/qiLiuyun.js';
	import request from '../../api/index.js'
	export default {
		mixins: [commonMixin],
		data() {
			return {
				imga: '',
				zhanshi: [],
				tupancli: [],
			};
		},
		async onLoad(e) {
			
			let th = this
			th.imga = JSON.parse(e.url)
			console.log(e)
			const key = await this.Tokenqiniu(this.imga, 'ali-search-ref')
			th.search(key)
				
		},
		methods: {
			eacha() {
				let th = this
				uni.chooseImage({
					count: 1,
					sourceType: ['camera', 'album'],
					crop: {
						width: 300,
						height: 300
					}, // 1:1 比例裁剪,
					success(res) {
						th.sousu(res.tempFilePaths[0])
					}
				})

			},
			async sousu(res) {
				this.imga = res
				const key = await this.Tokenqiniu(this.imga, 'ali-search-ref')
				this.search(key)
			},
			tiaoz(item) {
				uni.navigateTo({
					url: '/pages/jiemxiajia/jiemxiajia?id=' + item.goods_out_uuid
				});

			},
			tiaozhuan(text) {
				uni.navigateTo({
					url: '/pages/jiemxiajia/jiemxiajia?data=' + encodeURIComponent(JSON.stringify(text))
				});
			},
			async search(key) {
				let th = this;
				uni.showLoading({
					title: '搜索中...',
					mask: true // 防止触摸穿透[7](@ref)
				});
				// #ifdef MP-TOUTIAO
				let obj = {
					data: {
						imageKey: key
					},
					url: api.ctrl + '/dy/image-censor',
					method: "GET",
				}
				let res = await request(obj)
				if (res.data.error != 0) {
					uni.showToast({
					  title: '图片存在风险，请重新上传',     // 提示内容
					  icon: 'error',      // 图标类型（success/loading/none）
					  duration: 2000,        // 显示时长（毫秒）
					  mask: true,            // 是否遮罩（防止穿透点击）
					  position: 'top'        // 位置（top/center/bottom）
					})
				} else {
					uni.request({
						url: api.Channel + '/btn/image/search',
						method: "GET",
						data: {
							key
						},
						success(res) {
							console.log(res.data.data)
							if (res.data.code != 0) {
								uni.hideLoading();
								uni.showToast({
									title: '搜索失败请联系管理员',
									icon: "error",
									duration: 2000
								});
								return
							}
							uni.hideLoading();
							th.tupancli = res.data.data
						}
					})
					// console.log(imgs)
				}
				console.log()

				// #endif



				// #ifdef MP-WEIXIN
				uni.request({
					url: api.Channel + '/btn/image/search',
					method: "GET",
					data: {
						key
					},
					success(res) {
						console.log(res.data.data)
						if (res.data.code != 0) {
							uni.hideLoading();
							uni.showToast({
								title: '搜索失败请联系管理员',
								icon: "error",
								duration: 2000
							});
							return
						}
						uni.hideLoading();
						th.tupancli = res.data.data
					}
				})
				// console.log(imgs)
				// #endif


			}
		}
	}
</script>

<style>
	.eachjie-box {
		display: flex;
		justify-items: center;
		justify-content: center;
		padding-bottom: 50rpx;
		border-bottom: 1px solid gray;
	}
	
	.fixed-height-img {
	  height: 500rpx;             
	  width: auto;                
	  max-width: 100%;            
	  display: block;
	}


	.const-box-as {
		background-color: #ffff;
		border-radius: 30upx 30upx 10upx 10upx;

		margin-top: 30upx;
		position: relative;
	}

	.const-box {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		padding: 26upx;
	}

	.imgase {
		width: 50upx;
		position: absolute;
		top: 15upx;
		right: 15upx;
	}

	.textname {
		width: 45vw;
		text-align: center;
		font-size: 24rpx;
		white-space: nowrap;
		/* 不换行 */
		overflow: hidden;
		/* 隐藏超出部分 */
		text-overflow: ellipsis;
	}

	.imgaserrr {
		width: 320upx;
		height: 320upx;
	}
</style>